<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript">
	$(document).ready(function() {
        Page.render();

        var $lteTr = $('#lteTr').hide(), $gwTr = $('#gwTr').hide(),
            $tdsTr = $('#tdsTr').hide(),$bandStatus = $('#bandStatus').hide();

        var $btnSave = $('#btnSave');
		
        function getInfo() {
            Page.postJSON({
                json: {
                    cmd: RequestCmd.LOCK_BAND_GET
                },
                success: function(datas) {
                    if(!$.isEmptyObject(datas.band)){
                        var lte = datas.band.lte;
                        var gw = datas.band.gw;
                        var tds = datas.band.tds;
                        if(!$.isEmptyObject(lte)){
                            $lteTr.show();
                            var sb = new StringBuilder();
                            for ( var i = 0; i <lte.length; i++){
                                sb.append(String.format('<span><input type="checkbox" name="checkbox"  value="{0}">{1}</span>', lte[i],lte[i]));
                            }
                            $("'"+sb+"'").appendTo($('#lteDiv'));
                        }
                        if(!$.isEmptyObject(gw)){
                            $gwTr.show();
                            var sb1 = new StringBuilder();
                            for ( var j = 0; j <gw.length; j++){
                                sb1.append(String.format('<span><input type="checkbox" name="checkbox"  value="{0}">{1}</span>', gw[j],gw[j]));
                            }
                            $("'"+sb1+"'").appendTo($('#gwDiv'));
                        }
                        if(!$.isEmptyObject(tds)){
                            $tdsTr.show();
                            var sb2 = new StringBuilder();
                            for ( var x = 0; x <tds.length; x++){
                                sb2.append(String.format('<span><input type="checkbox" name="checkbox" value="{0}">{1}</span>', tds[x],tds[x]));
                            }
                            $("'"+sb2+"'").appendTo($('#tdsDiv'));
                        }

                    }else {
                        $bandStatus.show();
                        $bandStatus.html(DOC.lbl.noSim);
                        $btnSave.disable();
                    }

                    setlockban(datas.lockband);

                }
            });
        }

        getInfo();

        function setlockban(bandArr) {
            for ( var i = 0; i <bandArr.length; i++){
                $('input[name="checkbox"][value="'+bandArr[i]+'"]').prop('checked', true)
            }
        }

        $('input[name="allcheck"]').change(function(){
            if($('input[name="allcheck"]').prop("checked")){
                $('input[type="checkbox"]').prop("checked",true);
            }else{
                 $('input[type="checkbox"]').prop("checked",false);
            }
            
        })
        $btnSave.click(function() {
            $(this).attr("disabled",true);
            var check = new Array() ;
            var id = document.getElementsByName('checkbox');
            for (var i = 0; i < id.length; i++) {
                if (id[i].checked)
                    check.push(id[i].value);
            }
            var json = {band:check};
            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.LOCK_BAND_SET;
            Page.postJSON({
                json: json,
                success: function(data) {
                    AlertUtil.alertMsg(PROMPT.saving.success);
                    // $("ul.tabs a").eq(2).click();
                },
                complete: function(){
                    $('#btnSave').attr("disabled",false);
                }
            });
        })

        Page.setStripeTable();

    });

</script>

<div id="child_container">
    <script type="text/template" id="child_template">
        <table class="detail" cellspacing="0">

            <tr>
                <th></th>
                <td>
                    <span id="bandStatus" style = "font-size:18px;"></span>
                </td>
            </tr>


            <tr id="lteTr">
                <th style = "font-size:18px;">LTE<%- colon %></th>
                <td>
                    <div style="padding-left: 8px;font-size:18px"><input type="checkbox" name="allcheck"><%- DOC.lbl.all %></div>
                    <div id="lteDiv" class="bandDiv" ></div>
                </td>

            </tr>

            <tr id="gwTr">
                <th style = "font-size:18px;">GSM WCDMA<%- colon %></th>
                <td>
                    <div style="padding-left: 8px;font-size:18px"><input type="checkbox" name="allcheck"><%- DOC.lbl.all %></div>
                    <div id="gwDiv" class="bandDiv" ></div>
                </td>

            </tr>

            <tr id="tdsTr">
                <th style = "font-size:18px;">LTE<%- colon %></th>
                <td>
                    <div style="padding-left: 8px;font-size:18px"><input type="checkbox" name="allcheck"><%- DOC.lbl.all %></div>
                    <div id="tdsDiv" class="bandDiv"></div>
                </td>

            </tr>

            <tr id="trLockFreqBtns1">
                <th>&nbsp;</th>
                <td>
                    <input type="button" id="btnSave" value="<%- btn.save %>" class="btn" />
                </td>
            </tr>

        </table>
    </script>
</div>
